package com.quickd.service.service.wms.impl;

import com.quickd.core.service.impl.BaseServiceImpl;
import com.quickd.core.util.ConvertUtils;
import com.quickd.service.dto.wms.FormDTO;
import com.quickd.service.entity.wms.FormDetail;
import com.quickd.service.mapper.wms.FormMapper;
import com.quickd.service.entity.wms.Form;
import com.quickd.service.service.wms.IFormDetailService;
import com.quickd.service.service.wms.IFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 单据
 *
 * @author quickd quickd@dacanginfo.com
 * @since 2019-10-07
 */
@Service
public class FormServiceImpl extends BaseServiceImpl<FormMapper, Form> implements IFormService {
    @Autowired
    private IFormDetailService iFormDetailService;

    @Override
    @Transactional(rollbackFor =Exception.class ,propagation= Propagation.REQUIRED)
    public void addForm(FormDTO dto) {
        Form entity = ConvertUtils.sourceToTarget(dto, Form.class);
        baseDao.insert(entity);
        for(FormDetail formDetail:dto.getDataDetailList()){
            formDetail.setFormId(entity.getId());
        }
        iFormDetailService.saveBatch(dto.getDataDetailList());
    }
}